package cn.e3.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Service;

import cn.e3.easyuitreenode.EasyuiTreeNode;
import cn.e3.mapper.TbItemCatMapper;
import cn.e3.pojo.TbItemCat;
import cn.e3.pojo.TbItemCatExample;
import cn.e3.pojo.TbItemCatExample.Criteria;
import cn.e3.service.ItemCatService;
@Service
public class ItemCatServiceImpl implements ItemCatService{
	@Autowired
	private TbItemCatMapper itemCatMapper;
	//设置节点查询
	public List<EasyuiTreeNode> getItemCatList(long parentId) {
		//设置查询条件
		TbItemCatExample example=new TbItemCatExample();
		Criteria criteria = example.createCriteria();
		criteria.andParentIdEqualTo(parentId);
		//执行查询
		List<TbItemCat> list = itemCatMapper.selectByExample(example);
		List<EasyuiTreeNode> list1=new ArrayList<EasyuiTreeNode>();
		//查询结果设置在json对象中
		for (TbItemCat tbItemCat : list) {
			EasyuiTreeNode easyuiTreeNode=new EasyuiTreeNode();
			easyuiTreeNode.setId(tbItemCat.getId());
			easyuiTreeNode.setText(tbItemCat.getName());
			easyuiTreeNode.setState(tbItemCat.getIsParent()?"closed":"open");
			//将对象放入list集合
			list1.add(easyuiTreeNode);
		}
		
		return list1;
	}

}
